﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data;
using DreamBuilder.DictionaryAccess;

namespace DreamBuilder.UI.UserControls.DataAccess.Services
{
    public abstract class DDLReferenceDAL : UserControlsDataAccessBase
    {
        public IDataReader GetBindData(string tablecode, string whereSql)
        {
            TableDicInfo pTableDicInfo = DictionaryAccessFacade.GetTableDicInfo(tablecode);
            string primaryField = pTableDicInfo.PrimaryField;
            string displayField = pTableDicInfo.DisplayField;

            string sql = "select " + primaryField + "," + displayField + " from " + tablecode;

            if (!string.IsNullOrEmpty(whereSql))
            {
                sql += " where " + whereSql;
            }
            if (!string.IsNullOrEmpty(pTableDicInfo.OrderSql))
            {
                sql += " order by " + tablecode + "." + pTableDicInfo.OrderSql;
            }
            return DBHelper.ExecuteReader(sql);
        }

    }
}
